<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use \yii\db\ActiveRecord;
date_default_timezone_set("PRC");

/**
 * This is the model class for table "public_log".
 *
 * @property int $id
 * @property int $sys_id 对应的系统id
 * @property string $sys_name 系统名
 * @property string $gitee_name 仓库名
 * @property int|null $status 状态 0:未执行 1:发布完成 2:发布失败
 * @property string|null $ctime 发布时间
 * @property string|null $lutime 更新时间
 */
class PublicLog extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['ctime', 'lutime'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['lutime'],
                ],
                // if you're using datetime instead of UNIX timestamp:
                // 'value' => new Expression('NOW()'),
                'value' => function(){return date('Y-m-d H:i:s',time());},
            ],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'public_log';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['sys_id', 'sys_name', 'gitee_name'], 'required'],
            [['sys_id', 'status'], 'integer'],
            [['ctime', 'lutime'], 'safe'],
            [['sys_name'], 'string', 'max' => 20],
            [['gitee_name'], 'string', 'max' => 32],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'sys_id' => 'Sys ID',
            'sys_name' => 'Sys Name',
            'gitee_name' => 'Gitee Name',
            'status' => 'Status',
            'ctime' => 'Ctime',
            'lutime' => 'Lutime',
        ];
    }
}
